import { ref } from 'vue';

const state = ref<{ authKeys: string[]; roleMap: Map<string, Set<string>> }>({
  authKeys: [],
  roleMap: new Map<string, Set<string>>(),
});

function getAuthKey(): string[] {
  return state.value.authKeys;
}

function setAuthKey(authKeys: string[]) {
  state.value.authKeys = authKeys;
}

function setRoleMap(roleMap: string[]) {
  state.value.roleMap = roleMap;
}

function getRoleMap(): Map<string, Set<string>> {
  return state.value.roleMap;
}

export function useAuthState() {
  return {
    getAuthKey,
    setAuthKey,
    getRoleMap,
    setRoleMap,
    state,
  };
}
